﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="baseUrl" value="${pageContext.request.contextPath }"></c:set>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="${baseUrl }/css/style.css">
<script type="text/javascript">
	function doDel(id) {
		var flag = confirm("确认删除？");
		if(flag){
			window.location="${baseUrl }/UserController/deleteUser?id="+id
		}
	}
</script>
</head>
<body>
	<div class="menu">

		<table>
			<tbody>
				<tr>
					<td><form method="post" action="${baseUrl }/UserController/getAllUser">
								用户名称：<input name="userName"
								class="input-text" type="text" value="${userName }">&nbsp;&nbsp;&nbsp;&nbsp;
							<input value="查 询" type="submit">
						</form></td>
				</tr>
			</tbody>
		</table>
	</div>
	<div class="main">
		
		<div class="optitle clearfix">
		<c:if test="${user1.supers eq 1 }">
			<em><input value="添加数据" class="input-button"
				onclick="window.location='${baseUrl }/userAdd.jsp'" type="button"></em>
		</c:if>
			<div class="title">用户管理&gt;&gt;</div>
		</div>
		<div class="content">
			<table class="list">
				<tbody>
					<tr>
						<td width="70" height="29"><div class="STYLE1" align="center">序号</div></td>
						<td width="70" height="29"><div class="STYLE1" align="center">编号</div></td>
						<td width="80"><div class="STYLE1" align="center">用户名称</div></td>
						<td width="100"><div class="STYLE1" align="center">性别</div></td>
						<td width="100"><div class="STYLE1" align="center">年龄</div></td>

						<td width="150"><div class="STYLE1" align="center">电话</div></td>
						<td width="150"><div class="STYLE1" align="center">地址</div></td>
						<td width="150"><div class="STYLE1" align="center">权限</div></td>
						<c:if test="${user1.supers eq 1 }">
						<td width="150" colspan="2"><div class="STYLE1" align="center">操作</div></td>
						</c:if>
				
					</tr>
					<c:forEach items="${list }" var="user">
					<tr>
						<c:set value="${i+1 }" var="i"></c:set>
						<td height="23"><span class="STYLE1">${i }</span></td>
						<td height="23"><span class="STYLE1">${user.id }</span></td>
						<td><span class="STYLE1">${user.userName }</span></td>

						<td><c:if test="${user.sex==0 }"><span class="STYLE1">女</span></c:if>
							<c:if test="${user.sex==1 }"><span class="STYLE1">男</span></c:if>
						</td>
						<td><span class="STYLE1">${user.age }</span></td>
						<td><span class="STYLE1">${user.mobile }</span></td>
						<td><span class="STYLE1">${user.address }</span></td>
						<c:choose>
							<c:when test="${user.common eq 1 }">
								<td><span class="STYLE1">普通员工</span></td>
							</c:when>
							<c:when test="${user.supers eq 1 }">
								<td><span class="STYLE1">经理</span></td>
							</c:when>
						</c:choose>						
						<c:if test="${user1.supers eq 1 }">
						<td width="150" colspan="1">
							<a class="STYLE1" href="javascript:doDel(${user.id })">删除</a>
							<a class="STYLE1" href="${baseUrl }/UserController/getUserById?id=${user.id}">更新</a>
						</td>
						</c:if>
					</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
	</div>
	
	<c:url value="UserController/getAllUser" var="first">
		<c:param name="pageIndex" value="1"></c:param>
		<c:param name="userName" value="${userName }"></c:param>
	</c:url>
	<c:url value="UserController/getAllUser" var="forward">
		<c:param name="pageIndex" value="${pageIndex-1 }"></c:param>
		<c:param name="userName" value="${userName }"></c:param>
	</c:url>
	<c:url value="UserController/getAllUser" var="next">
		<c:param name="pageIndex" value="${pageIndex+1 }"></c:param>
		<c:param name="userName" value="${userName }"></c:param>
	</c:url>
	<c:url value="UserController/getAllUser" var="last">
		<c:param name="pageIndex" value="${totalPage }"></c:param>
		<c:param name="userName" value="${userName }"></c:param>
	</c:url>
	<font size="4" color="blue">
		<a href="${baseUrl }/${first }">首页</a>
	<!-- 当前页码等于1时隐藏"上一页" -->
	<c:if test="${pageIndex > 1 }">
		<a href="${baseUrl }/${forward }">上一页</a>
	</c:if>
	<!-- 当前页码为总页码时，隐藏"下一页" -->
	<c:if test="${pageIndex < totalPage }">
		<a href="${baseUrl }/${next }">下一页</a>
	</c:if>
		<a href="${baseUrl }/${last }">尾页</a>
	&nbsp;
		总共有<font color="red">${totalCount }</font>条数据，共<font color="red">${totalPage }</font>页
	</font>
</body>
</html>